<?php
/**
 * Created by PhpStorm.
 * User: zhan
 * Date: 2018/9/30  10:17
 */
namespace app\admin\controller;
use think\Db;
class Link extends Common
{
    private $table_admin = 'link';

    /*
	*	构造函数
	*/
    function __construct()
    {
        parent::__construct();
        $this->table_admin = db('link');
    }

    //列表
    public function lists()
    {
        $list = $this->table_admin->order('id desc')->paginate();
        $this->assign('list', $list);
        $this->assign('page', $list->render());
        return $this->fetch();
    }

    public function edit()
    {
        $type = input('type');
        $id = input('id');
        if(!empty($id)){
            $data = db('link')->where('id',$id)->find();
            $this->assign('da', $data);
        }
        
        $this->assign('type', $type);
        return $this->fetch();
    }

    //添加
    public function doedit()
    {
        $data = input();

        $data['created_at'] = time();

        if(empty($data['id'])){

            $res = db('link')->insert($data);

            if($res)return json(['msg'=>'更新成功']);

            return json(['msg'=>'更新失败']);
        }

        $res = db('link')->update($data);

        if($res)return json(['msg'=>'更新成功']);

        return json(['msg'=>'更新失败']);
    }

    public function del(){

        $id['id'] = input('id');

        $res = db('link')->delete($id);

        if($res)return json(['msg'=>'更新成功']);

        return json(['msg'=>'更新失败']);

    }
    
}
